package com.ktwlsoft.archivemanage.controller;

import com.ktwlsoft.archivemanage.domain.business.repositoryService.OperationRepositoryService;
import com.ktwlsoft.archivemanage.payload.Result;
import com.ktwlsoft.archivemanage.payload.operation.PageRequest;
import com.ktwlsoft.archivemanage.service.security.UserAuthenticate;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Api(value = "操作日志", description = "操作日志")
@RestController
@RequestMapping("/operation")
public class OperationDialogController {

    private final OperationRepositoryService operationRepositoryService;

    public OperationDialogController(OperationRepositoryService operationRepositoryService) {
        this.operationRepositoryService = operationRepositoryService;
    }

    @ApiOperation("分页查询")
    @GetMapping("/findByPage")
    @UserAuthenticate(actionCode = "OPERATION_LIST", skip = true)
    public ResponseEntity<?> findByPage(PageRequest request){
        return ResponseEntity.ok(Result.ok(operationRepositoryService.findByPage(request)));
    }

    @ApiOperation("列表查询")
    @GetMapping("/findList")
    public ResponseEntity<?> findList(@ApiParam(name = "operateFrom", value = "操作时间起") @RequestParam(defaultValue = "",required = false) String operateFrom,
                                      @ApiParam(name = "operateTo", value = "操作时间止") @RequestParam(defaultValue = "",required = false) String operateTo){
        return ResponseEntity.ok(Result.ok(operationRepositoryService.findList(operateFrom,operateTo)));
    }

    @ApiOperation("详情")
    @GetMapping("/findEditHistory")
    @UserAuthenticate(actionCode = "OPERATION_DETAIL", skip = true)
    public ResponseEntity<?> findEditHistory(@RequestParam @ApiParam("操作日志id") Long opId){
        return ResponseEntity.ok(Result.ok(Result.ok(operationRepositoryService.findDetailByOpId(opId))));
    }
}
